/*  File Name	: EventHandler.h
 *  Author		: Javie Pong
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-3-20
 *  Description:
 */

#ifndef EVENTHANDLER_H_
#define EVENTHANDLER_H_
#include "Header.h"
#include "Lock.h"
#include <signal.h>

#define INVALID_HANDLER -1
#define BIT_ENABLE(MASK,BITS) (MASK & BITS)!=0
#define SET_BITS(MASK,BITS) (MASK |=BITS)
#define CLR_BITS(MASK,BITS) (MASK &= ~BITS)

typedef unsigned long int ReactorMask;

class Reactor;

class EventHandler
{
public:
	enum
	{
		NULL_MASK 		= 0,
		READ_MASK 		= (1<<0),
		WRITE_MASK 		= (1<<1),
		EXCEPT_MASK 	= (1<<2),
		ACCEPT_MASK 	= (1<<3),
		CONNECT_MASK 	= (1<<4),
		TIMER_MASK 		= (1<<5),
		QOS_MASK 		= (1<<6),
		GROUP_QOS_MASK 	= (1<<7),
		SIGNAL_MASK 	= (1<<8),
		RWE_MASK 		= READ_MASK | WRITE_MASK|EXCEPT_MASK,
		ALL_MASK		= RWE_MASK |CONNECT_MASK|TIMER_MASK
							|QOS_MASK|GROUP_QOS_MASK|SIGNAL_MASK,
		DONT_CALL =(1<<9)
	};

	EventHandler();

	virtual ~EventHandler();

	virtual int handle_input(int handle);

	virtual int handle_output(int handle);

	virtual int handle_exception(int handle);

	virtual int handle_signal(int signum);

	virtual int handle_timeout(void);

	virtual int handle_exit(int pid);

	virtual int handle_close(int handle,ReactorMask mask);

	virtual void reactor(Reactor *reactor);

	virtual Reactor *reactor(void) const;

private:
	Reactor *reactor_;
};

#endif /* EVENTHANDLER_H_ */
